//
//  RepaymentViewController.m
//  51易借
//
//  Created by 张睿 on 2017/8/21.
//  Copyright © 2017年 张睿. All rights reserved.
//

#import "RepaymentViewController.h"
#import "BorrowRecodeController.h"
#import "HomePageModel.h"
#import "AppDelegate.h"
#import "LoginViewController.h"
#import "OrangeNavController.h"
#import "BorrowApplyViewController.h"
#import "WindowView.h"
#import "FinishInfoViewController.h"
#import "PayMentModel.h"
#import "ImmediatelyRepayController.h"

#import "FMDeviceManager.h"

@interface RepaymentViewController ()<windowViewDelegate>
@property (nonatomic, weak)UIView * topView;
@property (nonatomic, weak)UIImageView * logoImageView;
@property (nonatomic, weak)UIView * inputView;
@property (nonatomic, weak)UIView * backView;
@property (nonatomic,strong)PayMentModel * payModel;
@property (nonatomic, strong)WindowView * windowView;
@property (nonatomic, weak)UIImageView * showImageView;
@property (nonatomic, weak)UILabel * showLabel;
@property (nonatomic, weak)UIImageView * moneySymbol;
@property (nonatomic, strong)UIButton * thousandButton;
@property (nonatomic, strong)UIButton * hundredButton;
@property (nonatomic, strong)UIButton * tenButton;
@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, weak)UIView * lineView;
@property (nonatomic, weak)UIView * leftLineView;
@property (nonatomic, weak)UIView * rightLineView;
@property (nonatomic, weak)UIView * middleLineView;
@property (nonatomic, strong)UIView * middleLineView2;
@property (nonatomic, strong)UIView * leftLineView2;
@property (nonatomic, strong)UIView * rightLineView2;
@property (nonatomic, strong)UILabel * borrowLabel;
@property (nonatomic, strong)UILabel * criedtLabel;
@property (nonatomic, strong)UILabel * borrowDateLabel;
@property (nonatomic, strong)UILabel * borrowDateValueLabel;
@property (nonatomic, strong)UILabel * repaymentDateLabel;
@property (nonatomic, strong)UILabel * repaymentDateValueLabel;
@property (nonatomic, weak)UIButton * nextButton;
@property (nonatomic,strong)UIView * moneyView;
@property (nonatomic,strong)NSMutableArray * numbersViews;
@property (nonatomic,strong)UIView * dateView;
@property (nonatomic,strong)UIView * amountView;
@property (nonatomic,strong)UIView * emptyView;
@property (nonatomic,strong)UIImageView * faceView;
@property (nonatomic,strong)UILabel * labelView;


@end

@implementation RepaymentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = ColorWithRGB(0xf6f6f6);

    [self setupNavBar];
    [self setupUI];
}


- (void)setupNavBar{
    
    self.navigationController.navigationBar.translucent=YES;
    UIColor *color=[UIColor clearColor];
    CGRect rect =CGRectMake(0,0,self.view.frame.size.width,64);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context =UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:(UIBarMetricsDefault)];
    
    self.navigationController.navigationBar.clipsToBounds=YES;
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if([DEF_GET_OBJECT(userToken) length]){
      
        [self verifyStatus:^(NSInteger status) {
            [self updatePage];
            
        }];
    }else{
        
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        LoginViewController * loginVC = [LoginViewController new];
        
        loginVC.typeString = @"1";
        
        OrangeNavController * navVC = [[OrangeNavController alloc] initWithRootViewController:loginVC];
        
        appDelegate.window.rootViewController = navVC;
    }
}












-(void)setUpMoneyView:(NSInteger)money
{
    [self.moneyView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeFromSuperview];
    }];
    [self.numbersViews removeAllObjects];

    NSArray * numbers = [self nsinterLength:money];
    
//    NSLog(@"==%@",numbers);
    
    UIImageView * moneySymbol = [UIImageView new];
    
    moneySymbol.image = [UIImage imageNamed:@"¥"];
    
    [self.numbersViews addObject:moneySymbol];
    [self.moneyView addSubview:moneySymbol];
    for(NSString * number in numbers)
    {
        UIButton * button = [self setupButton:number];
        [self.moneyView addSubview:button];
        [self.numbersViews insertObject:button atIndex:1];
    }

}


- (NSArray*)nsinterLength:(NSInteger)x{
    if(x<=0)
        return @[@"0"];
    NSMutableArray * numbers = [NSMutableArray array];
    NSInteger sum=0,j=1;
    while( x >= 1 ) {
//        NSLog(@"%zd位数是 : %zd\n",j,x%10);
        [numbers insertObject:[NSString stringWithFormat:@"%zd",x%10] atIndex:0];
        x=x/10;
        sum++;
        j=j*10;
    }
    
    return numbers;
}



-(void)SetUpEmptyView
{
    self.faceView = [UIImageView new];
    self.faceView.image = [UIImage imageNamed:@"无"];
    self.labelView = [UILabel new];
    self.labelView.font = [UIFont systemFontOfSize:15*SCREENH6];
    self.labelView.textColor = [UIColor grayColor];
    self.labelView.text = @"目前无待还款账单";
    [self.emptyView addSubview:self.faceView];
    [self.emptyView addSubview:self.labelView];
}





-(void)setUpAmountView
{
    self.amountView.hidden = YES;
    self.borrowLabel = [self setupLabel:@"可借额度"];;
    self.criedtLabel = [self setupLabel:@"信用额度"];;
    self.criedtLabel.textAlignment = NSTextAlignmentRight;;
    self.leftLineView2 = [UIView new];
    self.rightLineView2 = [UIView new];
    self.middleLineView2 = [UIView new];
    self.leftLineView2.backgroundColor = ColorWithRGB(0xe6e6e6);
    self.rightLineView2.backgroundColor = ColorWithRGB(0xe6e6e6);
    self.middleLineView2.backgroundColor = ColorWithRGB(0xe6e6e6);
    [self.amountView addSubview:self.borrowLabel];
    [self.amountView addSubview:self.criedtLabel];
    [self.amountView addSubview:self.leftLineView2];
    [self.amountView addSubview:self.rightLineView2];
    [self.amountView addSubview:self.middleLineView2];


}
-(void)setUpDateView
{
    self.dateView.hidden = YES;
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xf6f6f6);
    
    self.lineView = lineView;
    
    [self.dateView addSubview:self.lineView];
    
    UIView * leftLineView = [UIView new];
    
    leftLineView.backgroundColor = ColorWithRGB(0xb8becc);
    
    self.leftLineView = leftLineView;
    
    [self.dateView addSubview:self.leftLineView];
    
    UIView * rightLineView = [UIView new];
    
    rightLineView.backgroundColor = ColorWithRGB(0xb8becc);
    
    self.rightLineView = rightLineView;
    
    [self.dateView addSubview:self.rightLineView];
    
    UIView * middleLineView = [UIView new];
    
    middleLineView.backgroundColor = ColorWithRGB(0xb8becc);
    
    self.middleLineView = middleLineView;
    
    [self.dateView addSubview:self.middleLineView];
    
    
    
    self.borrowDateLabel = [self setupLabel:@"借款日期"];
    
    [self.dateView addSubview:self.borrowDateLabel];
    
    self.borrowDateValueLabel = [self setupLabel:@"2017.06.21"];
    
    [self.dateView addSubview:self.borrowDateValueLabel];
    
    self.repaymentDateLabel = [self setupLabel:@"还款日期"];
    
    [self.dateView addSubview:self.repaymentDateLabel];
    
    self.repaymentDateValueLabel = [self setupLabel:@"2017.07.21"];
    
    [self.dateView addSubview:self.repaymentDateValueLabel];

}






- (void)setupUI{
    
    UIView * topView = [UIView new];
    
    topView.backgroundColor = ColorWithRGB(0xff7907);
    
    self.topView = topView;
    
    [self.view addSubview:self.topView];
    
    
    UIImageView * logoImageView = [UIImageView new];
    
    logoImageView.image = [UIImage imageNamed:@"logo"];
    
    self.logoImageView = logoImageView;
    
    [self.view addSubview:self.logoImageView];
    
    self.emptyView = [UIView new];
    [self.view addSubview:self.emptyView];

    
    [self SetUpEmptyView];
    
    
    
    UIView * inputView = [UIView new];
    
    inputView.backgroundColor = [UIColor whiteColor];
    
    self.inputView = inputView;
    self.inputView.hidden = YES;
    [self.view addSubview:self.inputView];
    
    UIImageView * showImageView = [UIImageView new];
    
    showImageView.image = [UIImage imageNamed:@"标题"];
    
    self.showImageView = showImageView;
    
    [self.inputView addSubview:self.showImageView];
    
    //Arial-BoldItalicMT
    UILabel * showLabel = [UILabel new];
    
    showLabel.text = @"未还金额";
    showLabel.textAlignment = NSTextAlignmentCenter;
    showLabel.textColor = ColorWithRGB(0xfff7b0);
    showLabel.font = [UIFont boldSystemFontOfSize:15 * SCREENH6];
    CGAffineTransform matrix = CGAffineTransformMake(1, 0, tanf(-15 * (CGFloat)M_PI / 180), 1, 0, 0);
    showLabel.transform = matrix;
    
    self.showLabel = showLabel;
    
    [self.showImageView addSubview:self.showLabel];

    self.moneyView = [UIView new];
    [self.inputView addSubview:self.moneyView];

    
    [self setUpMoneyView:0];

    
    self.dateView = [UIView new];
    self.dateView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.dateView];
    
    
    self.amountView = [UIView new];
    self.amountView.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:self.amountView];
    
    
    [self setUpDateView];
    [self setUpAmountView];
   
    
    
    
    
    UIButton * nextButton = [UIButton new];
    //300 * 42
    [nextButton setTitle:@"去还款" forState:UIControlStateNormal];
    [nextButton setBackgroundImage:[UIImage imageNamed:@"去还款"] forState:UIControlStateNormal];
    [nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [nextButton addTarget:self action:@selector(didNextButton) forControlEvents:UIControlEventTouchUpInside];
    nextButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.nextButton = nextButton;
    
    [self.view addSubview:self.nextButton];
}


- (UIButton *)setupButton:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    [button setBackgroundImage:[UIImage imageNamed:@"钱框"] forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:37 * SCREENH6];
    [button setTitleColor:ColorWithRGB(0xff6600) forState:UIControlStateNormal];
    button.adjustsImageWhenHighlighted = NO;
    
    return button;
}


- (UILabel *)setupLabel:(NSString *)title{
    
    UILabel * label = [UILabel new];
    
    label.text = title;
    label.textColor = ColorWithRGB(0x303c41);
    label.font = [UIFont systemFontOfSize:11 * SCREENH6];
    label.textAlignment = NSTextAlignmentCenter;
    
    return label;
}


- (void)viewDidLayoutSubviews{
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(190 * SCREENH6);
    }];
    
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view).offset(90 * SCREENH6);
        make.width.mas_equalTo(149 * SCREENH6);
        make.height.mas_equalTo(49 * SCREENH6);
    }];
    
    [self.inputView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topView.mas_bottom);
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(170 * SCREENH6);
    }];
    


    
    [self.showImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.inputView);
        make.centerX.mas_equalTo(self.inputView);
        make.height.mas_equalTo(48 * SCREENH6);
        make.width.mas_equalTo(193 * SCREENH6);
    }];
    
    [self.showLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.showImageView).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.showImageView).offset(5 * SCREENH6);
    }];
    
    
    [self.moneyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.inputView).offset(65);
        make.leading.mas_equalTo(self.inputView).offset(0);
        make.trailing.mas_equalTo(self.inputView).offset(0);;
        make.height.mas_equalTo(50 * SCREENH6);
    }];
    
    __block CGFloat totalWidth = 20+50*(self.moneyView.subviews.count-1);
    [self.moneyView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.moneyView);

            if(idx == 0)
            {
                make.width.mas_equalTo(20 * SCREENH6);
                make.height.mas_equalTo(27 * SCREENH6);
                make.leading.mas_equalTo(self.moneyView).offset((SCREEN_WIDTH-totalWidth)/2);
            }else
            {
                make.height.mas_equalTo(50 * SCREENH6);
                make.width.mas_equalTo(37 * SCREENH6);
                make.leading.mas_equalTo(self.moneyView).offset(((SCREEN_WIDTH-totalWidth)/2+33)+(idx-1)*50);

            }
        }];
        
    }];
    [self.dateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(68 * SCREENH6);
        make.top.mas_equalTo(self.inputView.mas_bottom);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.dateView);
        make.height.mas_equalTo(1 * SCREENH6);
        make.top.mas_equalTo(self.dateView);
    }];
    
    [self.leftLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.dateView).offset(44 * SCREENH6);
        make.height.mas_equalTo(1 * SCREENH6);
        make.bottom.mas_equalTo(self.dateView.mas_bottom).offset(-35 * SCREENH6);
        make.width.mas_equalTo(39 * SCREENH6);
    }];
    
    [self.rightLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.dateView.mas_trailing).offset(-44 * SCREENH6);
        make.bottom.height.width.mas_equalTo(self.leftLineView);
    }];
    
    [self.middleLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.dateView);
        make.centerY.mas_equalTo(self.leftLineView);
        make.width.mas_equalTo(1 * SCREENH6);
        make.height.mas_equalTo(13 * SCREENH6);
    }];
    
    [self.borrowDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(15 * SCREENH6);
        make.leading.mas_equalTo(self.leftLineView.mas_trailing).offset(19 * SCREENH6);
    }];
    
    [self.borrowDateValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.borrowDateLabel);
        make.top.mas_equalTo(self.borrowDateLabel.mas_bottom).offset(5 * SCREENH6);
    }];
    
    [self.repaymentDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.borrowDateLabel);
        make.trailing.mas_equalTo(self.rightLineView.mas_leading).offset(-22 * SCREENH6);
    }];
    
    [self.repaymentDateValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.repaymentDateLabel);
        make.centerY.mas_equalTo(self.borrowDateValueLabel);
    }];
    
    [self.amountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(50 * SCREENH6);
        make.top.mas_equalTo(self.inputView.mas_bottom);
    }];
    
    
    [self.middleLineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.amountView);
        make.top.mas_equalTo(self.amountView);
        make.width.mas_equalTo(1 * SCREENH6);
        make.height.mas_equalTo(13 * SCREENH6);
    }];
    
    [self.criedtLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.middleLineView2).offset(-5 * SCREENH6);
        make.top.mas_equalTo(self.amountView);
        make.height.mas_equalTo(13 * SCREENH6);
    }];
    [self.borrowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.middleLineView2).offset(5 * SCREENH6);
        make.top.mas_equalTo(self.amountView);
        make.height.mas_equalTo(13 * SCREENH6);

    }];
    [self.leftLineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.criedtLabel.mas_leading).offset(-5 * SCREENH6);
        make.height.mas_equalTo(1 * SCREENH6);
        make.centerY.mas_equalTo(self.criedtLabel);
        make.width.mas_equalTo(39 * SCREENH6);
    }];
    
    [self.rightLineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.borrowLabel.mas_trailing).offset(5 * SCREENH6);
        make.height.mas_equalTo(1 * SCREENH6);
        make.centerY.mas_equalTo(self.borrowLabel);
        make.width.mas_equalTo(39 * SCREENH6);
    }];
    
    
    [self.emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topView.mas_bottom);
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(240 * SCREENH6);
    }];

    [self.faceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.emptyView);
        make.centerY.mas_equalTo(self.emptyView).offset(-10 * SCREENH6);
        make.height.mas_equalTo(82 * SCREENH6);
        make.width.mas_equalTo(94 * SCREENH6);

    }];
    [self.labelView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.emptyView);
        make.top.mas_equalTo(self.faceView.mas_bottom).offset(20 * SCREENH6);
        make.height.mas_equalTo(15 * SCREENH6);
        
    }];

    [self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.inputView.mas_bottom).offset(170 * SCREENH6);
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(300 * SCREENH6);
        make.height.mas_equalTo(42 * SCREENH6);
    }];
}


- (void)didNextButton{
    if(self.payModel){
        switch ([self.payModel.currentUserStatus intValue]) {
            case 0:
            {
                AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
                
                LoginViewController * loginVC = [LoginViewController new];
                
                loginVC.typeString = @"1";
                
                OrangeNavController * navVC = [[OrangeNavController alloc] initWithRootViewController:loginVC];
                
                appDelegate.window.rootViewController = navVC;

                
            }
                break;
            case 1:
            {
                [self setupWindow];
                
//                // 获取设备管理器实例
//                FMDeviceManager_t *manager = [FMDeviceManager sharedManager];
//                
//                // 准备SDK初始化参数
//                NSMutableDictionary *options = [NSMutableDictionary dictionary];
//                
//                /*
//                 * SDK具有防调试功能，当使用xcode运行时(开发测试阶段),请取消下面代码注释，
//                 * 开启调试模式,否则使用xcode运行会闪退。上架打包的时候需要删除或者注释掉这
//                 * 行代码,如果检测到调试行为就会触发crash,起到对APP的保护作用
//                 */
//                // 上线Appstore的版本，请记得删除此行，否则将失去防调试防护功能！
//                [options setValue:@"allowd" forKey:@"allowd"];  // TODO
//                
//                // 指定对接同盾的测试环境，正式上线时，请删除或者注释掉此行代码，切换到同盾生产环境
//                //                 [options setValue:@"sandbox" forKey:@"env"]; // TODO
//                
//                // 此处替换为您的合作方标识
//                [options setValue:@"51yjk" forKey:@"partner"];
//                
//                // 使用上述参数进行SDK初始化
//                manager->initWithOptions(options);
//                
//                /*
//                 * 获取设备指纹黑盒数据，请确保在应用开启时已经对SDK进行初始化，切勿在get的时候才初始化
//                 * 如果此处获取到的blackBox特别长(超过400字节)，说明初始化尚未完成(一般需要1-3秒)，或者由于网络问题导致初始化失败，进入了降级处理
//                 * 降级不影响正常设备信息的获取，只是会造成blackBox字段超长，且无法获取设备真实IP
//                 * 降级数据平均长度在2KB以内,一般不超过3KB,数据的长度取决于采集到的设备信息的长度,无法100%确定最大长度
//                 */
//                NSString *blackBox = manager->getDeviceInfo();
//                NSLog(@"同盾设备指纹数据: %@", blackBox);
            }
                break;
            case 2:
            {
                BorrowApplyViewController * vc = [BorrowApplyViewController new];
                vc.from = @"Repay";
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
                break;
            case 3:
            {
//                BorrowRecodeController * immediateVC = [BorrowRecodeController new];
//                immediateVC.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:immediateVC animated:YES];
                [MBProgressHUD showHUDAddedTo:self.view animated:YES];
                
                NSDictionary * parameters = @{@"page":@1,@"limit":@10};
                
                [[NetworkTool manager] POST:@"loan/loadBorrowingRecordList.json" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
                    
                    NSString * code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
                    
                    if ([code isEqualToString:@"0"]) {
                        
                        [MBProgressHUD hideHUDForView:self.view animated:YES];
                        
                        NSArray * array = responseObject[@"data"];
                        NSDictionary * dict = array.firstObject;
                        
                        HIDDEN_TAB;
                        ImmediatelyRepayController * immediateVC= [ImmediatelyRepayController new];
                        immediateVC.loanID = [NSString stringWithFormat:@"%@",dict[@"applyNo"]];
//                        immediateVC.borrow = @"home";
                        
                        [self.navigationController pushViewController:immediateVC animated:YES];
                        
                        SHOW_TAB;
                    }else{
                        
                        NSString * string = [NSString stringWithFormat:@"%@",responseObject[@"message"]];
                        [self showHint:string];
                    }
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    
                    NSLog(@"==%@",error);
                    
                }];
            }
                break;
            default:
                break;
        }
        
    }
    

    
}


- (void)didCancelButton{
    
    [self.backView removeFromSuperview];
    [self.windowView removeFromSuperview];
}


- (void)didGoFinishVC{
    
    [self.backView removeFromSuperview];
    [self.windowView removeFromSuperview];
    
    HIDDEN_TAB;
    
    FinishInfoViewController * finishVc = [FinishInfoViewController new];
    
    [self.navigationController pushViewController:finishVc animated:YES];
    
    SHOW_TAB;
}


- (void)setupWindow{
    
    UIView * backView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    backView.backgroundColor = [UIColor blackColor];
    backView.alpha = 0.55;
    self.backView = backView;
    
    [self.tabBarController.view addSubview:self.backView];
    
    self.windowView = [[WindowView alloc] initWithFrame:CGRectMake(52 * SCREENH6, 250 * SCREENH6, 270 * SCREENH6, 135 * SCREENH6)];
    
    
    
    self.windowView.delegate = self;
    //    [self.navigationController.view addSubview:self.windowView];
    [self.tabBarController.view addSubview:self.windowView];
    
    //下面这段代码是 将bottomView调整到父视图的最上面
    [self.view bringSubviewToFront:self.windowView];
}

-(void)didSure:(BOOL)sure
{
    if(sure)
    {
        [self didGoFinishVC];
    }else
    {
        [self didCancelButton];
    }
}



-(void)verifyStatus:(void(^)())complete
{
    ParaModel*para = [ParaModel new];
    
    
    [[NetworkTool shareManager] POST:[Interfacefile getRepaymentOverview] Param:[para toDictionary] andWaitStr:@"" waitView:self.view success:^(id  _Nullable responseObject) {
        
//        NSLog(@"responseObject==%@",responseObject);
        if([[responseObject objectForKey:@"code"]intValue] ==0)
        {
            self.payModel = [[PayMentModel alloc] initWithDictionary:[responseObject objectForKey:@"data"] error:nil];
            complete();
        }else{
            
            [self showHint:[responseObject objectForKey:@"message"]];
            
            
        }
    } andFailure:^(NSError * _Nonnull error) {
        [self showHint:@"网络错误"];
    }];
    
}




-(void)updatePage
{
    switch ([self.payModel.currentUserStatus integerValue]) {
        case 0:
        {

            self.showLabel.text = @"目前无待还款账单";
            
            [self.nextButton setTitle:@"登录查看还款额度" forState:UIControlStateNormal];
            
            self.emptyView.hidden = NO;
            self.inputView.hidden = YES;
            self.amountView.hidden = YES;
            self.dateView.hidden = YES;
            
        }
            break;
        case 1:
        {
            self.showLabel.text = @"目前无待还款账单";
            
            [self.nextButton setTitle:@"申请借款" forState:UIControlStateNormal];
            
            self.emptyView.hidden = NO;
            self.inputView.hidden = YES;
            self.amountView.hidden = YES;
            self.dateView.hidden = YES;
            
        }
            break;
        case 2:
        {
            self.showLabel.text = @"目前无待还款账单";
            [self.nextButton setTitle:@"申请借款" forState:UIControlStateNormal];
            self.emptyView.hidden = YES;
            self.inputView.hidden = NO;
            self.amountView.hidden = NO;
            self.dateView.hidden = YES;
            self.criedtLabel.text = [NSString stringWithFormat:@"%d元   信用额度",[self.payModel.defaultCredit intValue]];
//            NSLog(@"==%@",self.payModel.ableLoanAmount);
            self.borrowLabel.text = [NSString stringWithFormat:@"可借额度   %d元",[self.payModel.ableLoanAmount intValue]];

            [self setUpMoneyView:[self.payModel.ableLoanAmount intValue]];
            [self layOutMoneyView];
        }
            break;
        default:
        {
            
            self.showLabel.text = @"未还金额";
            [self.nextButton setTitle:@"去还款" forState:UIControlStateNormal];
            self.emptyView.hidden = YES;
            self.inputView.hidden = NO;
            self.amountView.hidden = YES;
            self.dateView.hidden = NO;
            [self setUpMoneyView:[self.payModel.needPaybackAmount intValue]];
            self.borrowDateValueLabel.text = [Lahelper formattedTimeFromTimeInterval:[self.payModel.loanTime longLongValue]];
            self.repaymentDateValueLabel.text = [Lahelper formattedTimeFromTimeInterval:[self.payModel.overdueTime longLongValue]];

            [self layOutMoneyView];


        }
            break;
    }
    
}

-(void)layOutMoneyView
{
    __block CGFloat totalWidth = 20+50*(self.moneyView.subviews.count-1);
    [self.moneyView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.moneyView);
            
            if(idx == 0)
            {
                make.width.mas_equalTo(20 * SCREENH6);
                make.height.mas_equalTo(27 * SCREENH6);
                make.leading.mas_equalTo(self.moneyView).offset((SCREEN_WIDTH-totalWidth)/2);
            }else
            {
                make.height.mas_equalTo(50 * SCREENH6);
                make.width.mas_equalTo(37 * SCREENH6);
                make.leading.mas_equalTo(self.moneyView).offset(((SCREEN_WIDTH-totalWidth)/2+33)+(idx-1)*50);
                
            }
        }];
        
    }];
}



-(NSMutableArray*)numbersViews
{
    if(!_numbersViews)
    {
        _numbersViews = [NSMutableArray array];
    }
    return _numbersViews;
}

@end
